{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{if empty($data)}添加{else}修改{/if}题目</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_cate" id="add_questions" method="post" action="">
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                                <label class="col-sm-3 control-label">科目&nbsp;&nbsp;id：</label>
                                    <div class="col-sm-4 m-l-n">
                                        <select class="form-control" name="subject_id">
                                            {if $lists}
                                            {foreach name="lists" item="v"}
                                            <option value="{$v.id}" style="margin-left:55px;"{if condition="$v.parent_id eq 0"}disabled="disabled"{/if}{if condition="@$data['subject_id'] eq $v.id"}selected{/if}>{$v.lefthtml}{$v.name}</option>
                                            {/foreach}
                                            {/if}
                                        </select>
                                    </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位名称</label>
                            <div class="col-sm-4 m-l-n">
                                 <select class="form-control" name="grad_id">
                                    <option value="0">==请选择==</option>
                                    <?php foreach($grad as $key=>$v){?>
                                    <option value="{$v.id}" {if $v.id==@$data['grad_id']} selected {/if}>{$v.name}</option>
                                    <?php } ?>
                                 </select>
                             </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标&nbsp;&nbsp;题：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="title" value="{$data.title|default=''}">
                            </div>
                        </div>
                    
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">正&nbsp;&nbsp;确&nbsp;&nbsp;答&nbsp;&nbsp;案：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_a" type="text" class="form-control" name="answer_a" value="{$data.answer_a|default=''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">错&nbsp;&nbsp;误&nbsp;&nbsp;答&nbsp;&nbsp;案：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_b" type="text" class="form-control" name="answer_b" value="{$data.answer_b|default=''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">错&nbsp;&nbsp;误&nbsp;&nbsp;答&nbsp;&nbsp;案：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_c" type="text" class="form-control" name="answer_c" value="{$data.answer_c|default=''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">错&nbsp;&nbsp;误&nbsp;&nbsp;答&nbsp;&nbsp;案：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_d" type="text" class="form-control" name="answer_d" value="{$data.answer_d|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

$(function(){
    
    //初始化上传图片插件
    initUploadImg();
});

function uploadImgCallback(name,id,src){

    $('#cover_id_p_cover').val(src);
}

//切换按钮
$('input[type="checkbox"][name=status]').change(function() {
    $('input[name=status]').val($(this).get(0).checked ? 1: 0);
});
</script>

<script type="text/javascript">

    $(function(){
        $('#add_questions').ajaxForm({
            beforeSubmit: checkForm, 
            success: complete, 
            dataType: 'json'
        });
        
        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入标题',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
             if( '' == $.trim($('#answer_a').val())){
                layer.msg('请输入答案',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('#answer_b').val())){
                layer.msg('请输入答案',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('#answer_c').val())){
                layer.msg('请输入答案',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('#answer_d').val())){
                layer.msg('请输入答案',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('questions/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;   
            }
        }
     
    });

    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},                    
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>